﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using System.Device.Location;
using System.Windows.Media.Imaging;
using System.Windows.Resources;

namespace egco380
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
           
        void cur_rate()
        {
            for (int i = 0; i < 6; i++)
            {
                rate[i] = 0.0;
            }
         
            WebClient cur_rate_usd = new WebClient();
            cur_rate_usd.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cur_rate_DownloadStringCompleted);
            cur_rate_usd.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=USD", UriKind.RelativeOrAbsolute));
            WebClient cur_rate_hkd = new WebClient();
            cur_rate_hkd.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cur_rate_hkd_DownloadStringCompleted);
            cur_rate_hkd.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=HKD", UriKind.RelativeOrAbsolute));
            WebClient cur_rate_cny = new WebClient();
            cur_rate_cny.DownloadStringCompleted+=new DownloadStringCompletedEventHandler(cur_rate_cny_DownloadStringCompleted);
            cur_rate_cny.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=CNY", UriKind.RelativeOrAbsolute));
            WebClient cur_rate_gbp = new WebClient();
            cur_rate_gbp.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cur_rate_gbp_DownloadStringCompleted);
            cur_rate_gbp.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=GBP", UriKind.RelativeOrAbsolute));
            WebClient cur_rate_jpy = new WebClient();
            cur_rate_jpy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cur_rate_jpy_DownloadStringCompleted);
            cur_rate_jpy.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=JPY", UriKind.RelativeOrAbsolute));
            WebClient cur_rate_eur = new WebClient();
            cur_rate_eur.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cur_rate_eur_DownloadStringCompleted);
            cur_rate_eur.DownloadStringAsync(new Uri("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=THB&ToCurrency=EUR", UriKind.RelativeOrAbsolute));
        
        }

        void cur_rate_eur_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[5] = double.Parse(cur_rate.Value);

        }

        void cur_rate_jpy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[4] = double.Parse(cur_rate.Value);

        }

        void cur_rate_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[0] = double.Parse(cur_rate.Value);

        }

        void cur_rate_hkd_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[1] = double.Parse(cur_rate.Value);
        }
        void cur_rate_cny_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[2] = double.Parse(cur_rate.Value);
        }
        void cur_rate_gbp_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XElement cur_rate = XElement.Parse(e.Result);
            rate[3] = double.Parse(cur_rate.Value);
        }
    }

}